﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Popup_DailyAttendanceCheck : Popup
{
    static public bool s_IsShow = false; // 게임에서 딱한번만 뜨게 해주는 변수
    public UILabel m_BodyLabel;

    public override void AwakeInit()
    {
        transform.FindChild("Body").GetComponent<UIPanel>().enabled = false;
        transform.FindChild("BG").GetComponent<UIPanel>().enabled = false;
    }

    public override void StartInit()
    {
        int stampId = MyInfo.Instance.DailyStampId;
        int day = MyInfo.Instance.DailyStampCount;

        if (!s_IsShow && day > 0)   // 서버에서 못받아 오는등 DailyStampCount가 0이면 팝업 안띄움. DailyStampCount는 무조건 1이상임
        {       
            s_IsShow = true;

            transform.FindChild("Body").GetComponent<UIPanel>().enabled = true;
            transform.FindChild("BG").GetComponent<UIPanel>().enabled = true;
            
            m_BodyLabel.text = string.Format(m_BodyLabel.text, stampId, day);            
        }
        else
        {
            transform.FindChild("Body").GetComponent<UIPanel>().enabled = false;
            transform.FindChild("BG").GetComponent<UIPanel>().enabled = false;

            if (!Popup_DailyMissionList.s_IsShow) // 보여줘야 할때만 통신
            {                
                RestAPI.singleton.GetMyAchievementList(CallBackOfGetMyAchievementList);
            }
            else
            {                
                PopupManager.PopupPop(gameObject);
            }
        }
    }
    

    void CallBackOfGetMyAchievementList(Hashtable returnData)
    {
        RestAPI.singleton.GetMyAchievementValue(CallBackOfGetMyAchievementValue);
    }

    void CallBackOfGetMyAchievementValue(Hashtable returnData)
    {
        PopupManager.PopupPop(gameObject);

        if (!Popup_DailyMissionList.s_IsShow)  // 보여주고 다신 안보여줌
        {
            Popup_DailyMissionList.s_IsShow = true;
            PopupManager.PopupPush(PopupKind.Popup_DailyMissionList);
        }
    }


    public override void OnXFunc(GameObject obj)
    { 
        if (!Popup_DailyMissionList.s_IsShow) // 보여줘야 할때만 통신
        {
            isNeedClose = false;

            RestAPI.singleton.GetMyAchievementList(CallBackOfGetMyAchievementList);
        }        
    }
}
